import datetime
mytuple = ("apple", "banana", "cherry")

## 遍历tuple非常简单， 只需一个跌代器即可， 当然一定是需要这个数据类型支持跌代
myit = iter(mytuple)

print(next(myit))
print(next(myit))
print(next(myit))

myDict = {}
myDict["name"] = "ant-loiter"
myDict["content"] = "www.ant-loiter.com"
myDict["date"] = datetime.datetime.now()

iterDict = iter(myDict)

print(myDict.get(next(iterDict)))

mystr = "banana"
myit = iter(mystr)

print(next(myit))

for x in mytuple:
    print(x)

for x in mystr:
    print(x.rstrip('2').join(mytuple))


class MyNumbers:
    def __iter__(self):
        self.a = 1
        return self

    def __next__(self):
        x = self.a
        self.a += 1
        return x

myClass = MyNumbers()
myiter = iter(myClass)

print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print("====================")


class MyNumbers2:
    def __iter__(self):
        self.a = 1
        return self

    def __next__(self):
        if self.a <= 20:
            x = self.a
            self.a += 1
            return x
        else:
            raise StopIteration

myClass1 = MyNumbers2()
myitt = iter(myClass1)

for x in myitt:
    print(x)